<?php

/**
 * 添加文章
 */
$title = '公告设置';
include "header.php";
?>
<div class="row">
    <div class=" col-md-12 col-xl-12 col-lg-12">
        <div class="card">
            <div class="card-body">
                <div class="row">
                    <div class="col-md-12">
                        <h3 class="mb-3 header-title text-success"><?= $title ?></h3>
                        <form class="form-horizontal layui-form">
                            <div class="form-group mb-3" style="">
                                <label for="example-input-normal" style="position: relative;bottom: 0;left: 0">首页顶部公告</label>
                                <textarea class="form-control" name="notice_top" id="notice_top" rows="6" placeholder="请输入首页顶部公告内容"><?= $conf['notice_top'] ?></textarea>
                            </div>

                            <div class="form-group mb-3" style="">
                                <label for="example-input-normal" style="position: relative;bottom: 0;left: 0">首页查单公告</label>
                                <textarea class="form-control" name="notice_check" id="notice_check" rows="6" placeholder="请输入首页查单公告内容"><?= $conf['notice_check'] ?></textarea>
                            </div>


                            <div class="form-group mb-3" style="">
                                <label for="example-input-normal" style="position: relative;bottom: 0;left: 0">全局底部公告</label>
                                <textarea class="form-control" name="notice_bottom" id="notice_bottom" rows="6" placeholder="请输入全局底部公告内容"><?= $conf['notice_bottom'] ?></textarea>
                            </div>

                            <div class="form-group mb-3" style="">
                                <label for="example-input-normal" style="position: relative;bottom: 0;left: 0">用户后台公告</label>
                                <textarea class="form-control" name="notice_user" id="notice_user" rows="6" placeholder="请输入用户后台公告内容"><?= $conf['notice_user'] ?></textarea>
                            </div>

                            <div class="form-group mb-3" style="">
                                <label for="example-input-normal" style="position: relative;bottom: 0;left: 0">首页公告弹窗</label>
                                <textarea class="form-control" name="PopupNotice" id="PopupNotice" rows="6" placeholder="请输入用户后台公告内容"><?= $conf['PopupNotice'] ?></textarea>
                            </div>

                            <div class="form-group mb-3">
                                <label for="example-input-normal" style="font-weight: 500">添加客服界面的提示公告[支持html]</label>
                                <input type="text" name="ServiceTips" lay-verify="required" class="form-control" value="<?= $conf['ServiceTips'] ?>" placeholder="提示语">
                            </div>

                            <div class="form-group mb-3" style="">
                                <label for="example-input-normal" style="position: relative;bottom: 0;left: 0">IP统计代码
                                    [全局js代码也可以放到里面，如音乐播放器等！]</label>
                                <textarea class="form-control" name="statistics" rows="6" placeholder="请输入IP统计代码"><?= $conf['statistics'] ?></textarea>
                            </div>

                            <button type="submit" lay-submit lay-filter="Notification_set" class="btn btn-block btn-xs btn-success">保存内容
                            </button>
                        </form>

                        <span class="mt-3" style="display: block">若不懂代码,可点击：<span class="badge badge-primary-lighten" id="query_xc" style="cursor: pointer">获取小储系统的公告信息</span><span class="badge badge-info-lighten" id="query_ch" style="cursor: pointer">获取彩虹代刷的公告信息</span></span>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php include "bottom.php"; ?>
<link href="<?= $cdnpublic ?>summernote/0.8.12/summernote.css" rel="stylesheet">
<script src="<?= $cdnpublic ?>summernote/0.8.12/summernote.min.js"></script>
<script src="<?= $cdnpublic ?>summernote/0.8.12/lang/summernote-zh-CN.min.js"></script>
<script>
    //为了方便上传图片判断，分为4份
    $(document).ready(function() {
        $('#notice_top').summernote({
            lang: 'zh-CN',
            placeholder: '请输入首页顶部公告信息',
            minHeight: 200,
            callbacks: {
                onImageUpload: function(files, editor, $editable) {
                    UploadFiles(files, 'notice_top');
                }
            },
        });
        $('#notice_check').summernote({
            lang: 'zh-CN',
            placeholder: '请输入查单界面公告信息',
            minHeight: 200,
            callbacks: {
                onImageUpload: function(files, editor, $editable) {
                    UploadFiles(files, 'notice_check');
                }
            },
        });
        $('#notice_bottom').summernote({
            lang: 'zh-CN',
            placeholder: '请输入全局底部公告信息',
            minHeight: 200,
            callbacks: {
                onImageUpload: function(files, editor, $editable) {
                    UploadFiles(files, 'notice_bottom');
                }
            },
        });
        $('#notice_user').summernote({
            lang: 'zh-CN',
            placeholder: '请输入店长后台公告信息',
            minHeight: 200,
            callbacks: {
                onImageUpload: function(files, editor, $editable) {
                    UploadFiles(files, 'notice_user');
                }
            },
        });
        $('#PopupNotice').summernote({
            lang: 'zh-CN',
            placeholder: '请输入首页公告弹窗！',
            minHeight: 200,
            callbacks: {
                onImageUpload: function(files, editor, $editable) {
                    UploadFiles(files, 'PopupNotice');
                }
            },
        });

        function UploadFiles(files, id) {
            var imageData = new FormData();
            $.each(files, function(key, val) {
                imageData.append("imageData" + key, val);
            });
            $.ajax({
                data: imageData,
                type: "POST",
                url: "ajax.php?act=image_content",
                cache: false,
                contentType: false,
                processData: false,
                success: function(imageUrl) {
                    if (imageUrl.code == 1) {
                        var content = '';
                        $.each(imageUrl['SrcArr'], function(key, val) {
                            $('#' + id).summernote('editor.insertImage', val['src']);
                            content += '图片：<font color=red>' + val['name'] + '</font>大小为：<font color=red>' + val['size'] + '</font><br>';
                        });
                        layer.alert(content + '<hr>Ps:图片可一次上传多张！', {
                            title: imageUrl.msg
                        });
                    } else layer.msg(imageUrl.msg);
                },
                error: function() {
                    layer.msg('图片上传接口异常，上传失败！');
                }
            })
        }
    });
    layui.use('form', function() {
        var form = layui.form;
        form.on('submit(Notification_set)', function(data) {
            data.field['notice_top'] = $('#notice_top').summernote('code');
            data.field['notice_check'] = $('#notice_check').summernote('code');
            data.field['notice_bottom'] = $('#notice_bottom').summernote('code');
            data.field['notice_user'] = $('#notice_user').summernote('code');
            data.field['PopupNotice'] = $('#PopupNotice').summernote('code');
            layer.alert('是否要执行当前操作', {
                icon: 3,
                btn: ['确定', '取消'],
                btn1: function(layero, index) {
                    var index = layer.msg('数据保存中,请稍后...', {
                        icon: 16,
                        time: 999999
                    });
                    $.post('ajax.php?act=config_set', data.field, function(res) {
                        if (res.code == 1) {
                            layer.close(index);
                            layer.alert(res.msg, {
                                btn1: function(layero, index) {
                                    location.reload();
                                }
                            });
                        } else {
                            layer.close(index);
                            layer.alert(res.msg, {
                                btn1: function(layero, index) {
                                    location.reload();
                                }
                            });
                        }
                    });
                }
            });
            return false;
        })
    });
    $("#query_xc").click(function() {
        var index2 = layer.prompt({
            formType: 3,
            value: '',
            title: '请输入小储云商城站点,需加http://',
        }, function(value, index, elem) {
            var index = layer.msg('公告数据获取中,请稍后...', {
                icon: 16,
                time: 999999
            });
            $.post('ajax.php?act=Get_notice_xc', {
                url: value
            }, function(res) {
                if (res.code == 1) {
                    layer.closeAll();
                    $.each(res.data, function(index, value) {
                        $('#' + index).summernote('code', value);
                    });
                    layer.alert(res.msg, {
                        icon: 1
                    });
                } else {
                    layer.closeAll();
                    layer.alert(res.msg, {
                        icon: 2
                    });
                }
            });
        });
    });
    $("#query_ch").click(function() {
        var index2 = layer.prompt({
            formType: 3,
            value: '',
            title: '请输入彩虹代刷站点,需加http://',
        }, function(value, index, elem) {
            var index = layer.msg('公告数据获取中,请稍后...', {
                icon: 16,
                time: 999999
            });
            $.post('ajax.php?act=Get_notice_ch', {
                url: value
            }, function(res) {
                layer.closeAll();
                if (res.code == 1) {
                    $.each(res.data, function(index, value) {
                        $('#' + index).summernote('code', value);
                    });
                    layer.alert(res.msg, {
                        icon: 1
                    });
                } else {
                    layer.closeAll();
                    layer.alert(res.msg, {
                        icon: 2
                    });
                }
            });
        });
    })
</script>